import { Body, Controller, Delete, Param, Post, Get } from '@nestjs/common';
import { SignInDto } from './dto/sign-in.dto';
import { AuthService } from './auth.service';
import { SignUpDto } from './dto/sign-up.dto';
import { UserEntity } from '../user/entities/user.entity';
import { Public } from '../../common/decorators/public.decorator';
import axios from 'axios';
@Controller('auth')
export class AuthController {
  constructor(private readonly authService: AuthService) {}

  @Post('sign-up')
  @Public() // 白名单
  signUp(@Body() signUpDto: SignUpDto) {
    return this.authService.signUp(signUpDto);
  }

  @Post('sign-in')
  @Public()
  signIn(@Body() signInDto: SignInDto) {
    return this.authService.signIn(signInDto);
  }

  @Post('update')
  update(@Body() user: UserEntity) {
    return this.authService.update(user);
  }

  @Post('updateAvatar')
  updateAvatar(@Body() user: UserEntity) {
    return this.authService.updateAvatar(user.id, user.avatar);
  }

  @Delete('del/:id')
  del(@Param('id') id: string | number) {
    return this.authService.delUser(id);
  }

  // 获取随机毒鸡汤
  @Get('dujitang')
  @Public() // 白名单
  async dujitang() {
    return (
      await axios.get(
        `https://api.likepoems.com/ana/dujitang?time=${String(
          new Date().getTime(),
        )}`,
      )
    ).data;
  }
}
